package web;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;
public class Users {
	
	public static User getUser(int uid) throws SQLException, ClassNotFoundException{
		Batis b=new Batis();
		SqlSession session=b.myBatis();
		String statement = "me.bbs.map.bbsMapper.getUser";
		
	    User u=session.selectOne(statement,uid);
	    session.close();
	    return u;
	}
	public static String checkUser(int uid) throws SQLException, ClassNotFoundException{
		Batis b=new Batis();
		SqlSession session=b.myBatis();
		String statement = "me.bbs.map.bbsMapper.checkUser";
	    String s=session.selectOne(statement,uid);
	    session.close();
	    return s;
	}
	public static void addUser(int uid,String uname,String pword) throws ClassNotFoundException, SQLException{
		Batis b=new Batis();
		SqlSession session=b.myBatis();
		String statement = "me.bbs.map.bbsMapper.addUser";
		User u=new User();
		u.setUid(uid);
		u.setUname(uname);
		u.setPword(pword);
		session.insert(statement,u);
		session.close();
	}
	public static int checkUname(String uname) throws SQLException, ClassNotFoundException{
		Batis b=new Batis();
		SqlSession session=b.myBatis();
		String statement = "me.bbs.map.bbsMapper.checkUname";
		
		int i=session.selectOne(statement,uname);
		
	    session.close();
	    return i;
	}
}
